﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Carbon.Web.Forms.jQueryForms
{
    public interface IRadioButtonListItemCollection : IListEditorItemCollection
    {
        int? SelectedIndex { get; set; }
        bool CanSelectNone { get; }
    }

    [Serializable]
    public class RadioButtonListItemCollection<T> : ListEditorItemCollection<T>, IRadioButtonListItemCollection
    {
        public override object Clone()
        {
            RadioButtonListItemCollection<T> collection = new RadioButtonListItemCollection<T>(this.NameGenerator, this.SelectedIndex, this.CanSelectNone);
            CloneRadioButtonListItemCollectionProperties(this);
            return collection;
        }

        protected void CloneRadioButtonListItemCollectionProperties(RadioButtonListItemCollection<T> collection)
        {
            base.CloneListEditorItemCollectionProperties(collection);
        }

        private int? m_SelectedIndex = default(int?);
        public int? SelectedIndex
        {
            get
            {
                return m_SelectedIndex;
            }
            set
            {
                m_SelectedIndex = value;
            }
        }

        private bool m_CanSelectNone = default(bool);
        public bool CanSelectNone
        {
            get
            {
                return m_CanSelectNone;
            }
            set
            {
                m_CanSelectNone = value;
            }
        }

        public RadioButtonListItemCollection(IEnumerable<ListEditorItem<T>> collection, Func<T, string> nameGenerator, int? selectedIndex, bool canSelectNone)
            : base(collection, nameGenerator)
        {
            if (selectedIndex == null) throw new ArgumentNullException("selectedIndex");

            this.m_SelectedIndex = selectedIndex;
            this.m_CanSelectNone = canSelectNone;
        }
        public RadioButtonListItemCollection(int capacity, Func<T, string> nameGenerator, int? selectedIndex, bool canSelectNone)
            : base(capacity, nameGenerator)
        {
            if (selectedIndex == null) throw new ArgumentNullException("selectedIndex");

            this.m_SelectedIndex = selectedIndex;
            this.m_CanSelectNone = canSelectNone;
        }
        public RadioButtonListItemCollection(Func<T, string> nameGenerator, int? selectedIndex, bool canSelectNone)
            : base(nameGenerator)
        {
            if (selectedIndex == null) throw new ArgumentNullException("selectedIndex");

            this.m_SelectedIndex = selectedIndex;
            this.m_CanSelectNone = canSelectNone;
        }
        public RadioButtonListItemCollection(IEnumerable<T> objects, Func<T, string> nameGenerator, bool defaultValue, int? selectedIndex, bool canSelectNone)
            : base(objects, nameGenerator, defaultValue)
        {
            if (selectedIndex == null) throw new ArgumentNullException("selectedIndex");

            this.m_SelectedIndex = selectedIndex;
            this.m_CanSelectNone = canSelectNone;
        }


    }
}
